<?php include("header.php") ?>

<DIV id="prepage" style="font-family:arial; font-size:20; left:40%; top:0px; background-color:white; layer-background-color:white; height:100%; width:100%;"> 
<TABLE width=100%><TR><TD align="center"><img src="images/bluespinner.gif"  height="42" width="42"/></TD></TR><TR><TD align="center"><font size="4."><B>Deleting ... ... Please wait!</B></font></TD><TD></TD></TR></TABLE>
</DIV>



<?php
include("fileop.php");
$pic_loc = $_POST["selectedid"];

mysql_connect(DBADDR, DBUSER, DBPWD)or die("cannot connect");
mysql_select_db(DBNAME)or die("cannot select DB");
mysql_query('set names utf8'); 

$sql = "SELECT `RESTO_ID` FROM `resto_pic` WHERE `PIC_LOCATION` = '".$pic_loc."'";
$rs_result = mysql_query ($sql);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$rs_result) {
	$message  = 'Invalid query: ' . mysql_error() . "\n";
	$message .= 'Whole query: ' . $sql;
	die($message);
}
$row = mysql_fetch_assoc($rs_result);
$resto_id = $row['RESTO_ID'];

$con=mysqli_connect(DBADDR,DBUSER,DBPWD,DBNAME);
// Check connection
if (mysqli_connect_errno()){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  echo "Returning in 5 seceonds";
  header("refresh:5;url=allphoto.php");
}


mysqli_query($con,"DELETE FROM resto_pic WHERE PIC_LOCATION='".$pic_loc."'");

mysqli_close($con);

//Delete pic
delete_file($pic_loc);

header("Location:allphoto.php?succ=1&id=".$resto_id);


?>